home *** CD-ROM | disk | FTP | other *** search
/ Apple Service Source 1997 December / Service Source v2.5 Companion 1.iso / Macintosh / Utilities / AMK Spinning Cursor Bug Fix / CURSOR.c < prev    next >
Encoding:
C/C++ Source or Header  |  1995-05-25  |  3.2 KB  |  156 lines  |  [TEXT/MPS ]

  1. /*
  2.    File: CURSOR.c
  3.    Folder: RUNTIME
  4.    (c) Encore Développement, SARL, 1992-94
  5. */
  6.  
  7. #include "Memory.h"
  8. #include "QuickDraw.h"
  9. #include "Retrace.h"
  10.  
  11. #include "Key.h"
  12.  
  13. extern const keyID K_DATA;
  14. extern const keyID K_ID;
  15.  
  16. extern const keyID K_COUNT;
  17. extern const keyID K_GETAT;
  18.  
  19. void CursorLoad(key* the)
  20. {
  21.     short anID;
  22.     CCrsrHandle aCCrsrHandle;
  23.     
  24.     anID = keyToInteger(keyGet(the[SELF], K_ID));
  25.     aCCrsrHandle = GetCCursor(anID);
  26.     keyIfNULL(aCCrsrHandle);
  27.     keyPut(the[SELF], K_DATA, keyFromHandle(aCCrsrHandle));
  28. }
  29.  
  30. void CursorSet(key* the)
  31. {
  32.     CCrsrHandle aCCrsrHandle;
  33.     
  34.     aCCrsrHandle = (CCrsrHandle)keyToHandle(keyGet(the[SELF], K_DATA));
  35.     keyCheck(aCCrsrHandle != NULL);
  36.     SetCCursor(aCCrsrHandle);
  37. }
  38.  
  39. void CursorUnload(key* the)
  40. {
  41.     CCrsrHandle aCCrsrHandle;
  42.     
  43.     aCCrsrHandle = (CCrsrHandle)keyToHandle(keyGet(the[SELF], K_DATA));
  44.     keyCheck(aCCrsrHandle != NULL);
  45.     DisposCCursor(aCCrsrHandle);
  46.     keyPut(the[SELF], K_DATA, keyVoid);
  47. }
  48.  
  49. typedef struct {
  50. #ifdef applec
  51.     long globalA5;
  52.     long localA5;
  53. #endif
  54.     VBLTask task;
  55.     short running;
  56.     short index;
  57.     short count;
  58.     CCrsrPtr cursors[64];
  59. } SpinRecord, *SpinPtr;
  60.  
  61. SpinRecord gSpinRecord;
  62.  
  63. #ifdef applec
  64. pascal long GetA0() = { 0x2e88 };
  65. pascal long GetA5() = { 0x2e8d };
  66. #endif
  67.  
  68. pascal void SpinVBLTask()
  69. {
  70. #ifdef applec
  71.     SpinPtr aSpinPtr = (SpinPtr)(GetA0() - (sizeof(long) * 2));
  72.     aSpinPtr->localA5 = SetA5(aSpinPtr->globalA5);
  73. #endif
  74. #ifdef powerc
  75.     SpinPtr aSpinPtr = &gSpinRecord;
  76. #endif
  77.     aSpinPtr->task.vblCount = 10;
  78.     aSpinPtr->index++;
  79.     if (aSpinPtr->index == aSpinPtr->count) {
  80.         aSpinPtr->index = 0;
  81.     }
  82.     
  83.     /*     
  84.     Use the b&w cursor inside the locked color cursor handle
  85.     so it does not move memory...
  86.     */
  87.     
  88.     SetCursor((Cursor*)&((aSpinPtr->cursors[aSpinPtr->index])->crsr1Data));
  89. #ifdef applec
  90.     SetA5(aSpinPtr->localA5);
  91. #endif
  92. }
  93.  
  94. void SpinIsRunning(key* the)
  95. {
  96.     the[RESULT] = keyFromBoolean(gSpinRecord.running);
  97. }
  98.  
  99. void SpinStart(key* the)
  100. {
  101.     static VBLUPP aVBLUPP = NULL;
  102.  
  103.     short aCount, anIndex;
  104.     Handle aHandle;
  105.     
  106.     if (aVBLUPP == NULL) {
  107.         aVBLUPP = NewVBLProc(SpinVBLTask);
  108.     }
  109.     
  110.     aCount = keyToInteger(keyCall0(the[SELF], K_COUNT));
  111.     for (anIndex = 0; anIndex < aCount; anIndex++) {
  112.         the[RESULT] = keyCall1(the[SELF], K_GETAT, keyFromInteger(anIndex + 1));
  113.         aHandle = keyToHandle(keyGet(the[RESULT], K_DATA));
  114.         HLock(aHandle);
  115.         gSpinRecord.cursors[anIndex] = (CCrsrPtr)*aHandle;
  116.     }
  117.     
  118. #ifdef applec
  119.     gSpinRecord.globalA5 = GetA5();
  120. #endif
  121.     gSpinRecord.task.qType = vType;
  122.     gSpinRecord.task.vblAddr = aVBLUPP;
  123.     gSpinRecord.task.vblCount = 10;
  124.     gSpinRecord.task.vblPhase = 0;
  125.     gSpinRecord.index = 0;
  126.     gSpinRecord.count = aCount;
  127.     if (VInstall((QElemPtr)&(gSpinRecord.task)) == noErr) {
  128.         gSpinRecord.running = 1;
  129.     }
  130. }
  131.  
  132. void SpinStop(key* the)
  133. {
  134.     short aCount, anIndex;
  135.     Handle aHandle;
  136.  
  137.     if (VRemove((QElemPtr)&(gSpinRecord.task)) == noErr) {
  138.         gSpinRecord.running = 0;
  139.     }
  140.     aCount = keyToInteger(keyCall0(the[SELF], K_COUNT));
  141.     for (anIndex = 0; anIndex < aCount; anIndex++) {
  142.         the[RESULT] = keyCall1(the[SELF], K_GETAT, keyFromInteger(anIndex + 1));
  143.         aHandle = keyToHandle(keyGet(the[RESULT], K_DATA));
  144.         HUnlock(aHandle);
  145.         gSpinRecord.cursors[anIndex] = NULL;
  146.     }
  147. }
  148.  
  149. void CursorsShow(key *the)
  150. {
  151.     if (keyIsTrue(the[ARGUMENT(1)])) 
  152.         ShowCursor();
  153.     else 
  154.         HideCursor();
  155. }
  156.